/**
 * 获取缩放比例
 * @param width 设计稿宽度
 * @param height 设计稿高度
 * @returns 缩放比例
 */
export function getScale(width: number = 1920, height: number = 1080): number {
  // 确保只在浏览器环境中执行
  if (typeof window === "undefined") {
    return 1;
  }

  const scaleX: number = window.innerWidth / width;
  const scaleY: number = window.innerHeight / height;
  const scale: number = Math.min(scaleX, scaleY); // 保持等比
  return scale;
}

function scaleApp(width: number = 1920, height: number = 1080): void {
  // 确保只在浏览器环境中执行
  if (typeof window === "undefined" || typeof document === "undefined") {
    return;
  }

  const app = document.getElementById("app");
  if (!app) {
    console.warn("未找到id为app的元素");
    return;
  }

  const scale: number = getScale(width, height);
  app.style.width = `${width}px`;
  app.style.height = `${height}px`;
  app.style.transformOrigin = "left top";
  app.style.transform = `scale(${scale})`;
}

export default scaleApp;
